package com.mifengs.mall.floor;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.annotation.ItemProviderTag;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.mifengs.mall.R;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.entity.BannerBean;
import com.mifengs.mall.entity.FloorBean;
import com.mifengs.mall.loader.GlideImageLoader;
import com.mifengs.mall.util.ImageLoadUtil;
import com.mifengs.mall.util.ToIntentUtil;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;

import java.util.List;

/**
 * Created by lynn on 2018/4/19.
 */

@ItemProviderTag(
        viewType = FloorListAdapter.TYPE_FOUR,
        layout = R.layout.fragment_four_floor
)
public class FloorFourItemProvider extends BaseItemProvider<FloorBean,BaseViewHolder> {
    @Override
    public void convert(BaseViewHolder viewHolder, final FloorBean floorBean, int index) {
        Banner banner = viewHolder.getView(R.id.banner);
        ImageView four_floor_one_img = viewHolder.getView(R.id.four_floor_one_img);
        ImageView four_floor_two_img = viewHolder.getView(R.id.four_floor_two_img);
        ImageView four_floor_three_img = viewHolder.getView(R.id.four_floor_three_img);
        ImageView four_floor_four_img = viewHolder.getView(R.id.four_floor_four_img);
        ImageView four_floor_five_img = viewHolder.getView(R.id.four_floor_five_img);
        ImageView four_floor_six_img = viewHolder.getView(R.id.four_floor_six_img);
        ImageView four_floor_seven_img = viewHolder.getView(R.id.four_floor_seven_img);
        if(floorBean !=null){
            if(floorBean.getBanners().size()>0){
                banner.setVisibility(View.VISIBLE);
                List<BannerBean> banners = floorBean.getBanners();
                banner.setImages(banners)
                        .setImageLoader(new GlideImageLoader())
                        .setDelayTime(5000)
                        .setOnBannerListener(new OnBannerListener() {
                            @Override
                            public void OnBannerClick(int position) {
                                ToIntentUtil.toCommonIntent(floorBean.getBanners().get(position).getActionUrl(),mContext);
                            }
                        })
                        .start();
            }else{
                banner.setVisibility(View.GONE);
            }
            for(int i = 0;i<floorBean.getAdverts().size();i++ ){
                AdvertBean adverts = floorBean.getAdverts().get(i);
                switch (i){
                    case 0:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_one_img);
                        break;
                    case 1:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_two_img);
                        break;
                    case 2:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_three_img);
                        break;
                    case 3:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_four_img);
                        break;
                    case 4:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_five_img);
                        break;
                    case 5:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_six_img);
                        break;
                    case 6:
                        ImageLoadUtil.displayImage(mContext,adverts.getImg(),four_floor_seven_img);
                        break;
                }
            }

            four_floor_one_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(0);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            four_floor_two_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(1);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            four_floor_three_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(2);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            four_floor_four_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(3);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            four_floor_five_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(4);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            four_floor_six_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(5);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
            four_floor_seven_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    AdvertBean adverts = floorBean.getAdverts().get(6);
                    ToIntentUtil.toCommonIntent(adverts.getActionUrl(),mContext);
                }
            });
        }
    }

    @Override
    public void onClick(BaseViewHolder baseViewHolder, FloorBean floorBean, int i) {

    }

    @Override
    public boolean onLongClick(BaseViewHolder baseViewHolder, FloorBean floorBean, int i) {
        return false;
    }
}
